﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Graphing.Model;
using System.Collections.ObjectModel;

namespace Graphing.Services
{
    class ScaleService
    {
        #region Fields

        ObservableCollection<Point> PointsList = GenericSingleton<ObservableCollection<Point>>.GetInstance();

        #endregion // Fields.

        #region ComputateScale

        public Scale ComputateScale()
        {
            Scale _graphScale;
            Point[] pointsArray = PointsList.ToArray();
            List<double> xList = new List<double>();
            List<double> yList = new List<double>();

            //Go through Point list and grab X and Y values
            foreach (Point i in pointsArray)
            {
                xList.Add(i.x);
                yList.Add(i.y);
            }

            //Create a scale with the min and max of X and Y
            _graphScale = new Scale(xList.Min(), xList.Max(), yList.Min(), yList.Max());

            return _graphScale;
        }
        
        #endregion // ComputateScale.
    }

    
}
